package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-08-14
 * Time: 8:50
 */
public class demo11 {
    private static long result = 0;
    public static void main(String[] args) throws InterruptedException {
        // 创建一个线程, 让这个线程计算 1 + 2 + 3 + ... + 1000 => 500500
        // 主线程在这个计算线程执行完毕后, 打印此处的结果.
        Thread t = new Thread(()->{
            for(int i = 1; i <= 1000_0000; i++){
                result += i;
            }
        });
        t.start();
        t.join();   //让主线程等待t线程执行完后, 再继续执行
        System.out.println(result);
    }
}
